home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / mg2a_src.zip / SYS / AMIGA / DIRIO.C < prev    next >
C/C++ Source or Header  |  1988-08-23  |  1KB  |  52 lines

  1. /*
  2.  * Name:    MG 2x
  3.  *        Directory I/O routines, by Stephen Walton
  4.  *        Version of 5-May-88
  5.  */
  6.  
  7. #ifndef NO_DIR
  8.  
  9. #include "sysdef.h"
  10. #include <libraries/dosextens.h>
  11. #include <exec/memory.h>
  12.  
  13. extern    char        MyDirName[MAXPATH], *strncat();
  14.  
  15. char *getwd(path)
  16. char *path;
  17. {
  18.     strcpy(path,MyDirName);
  19.     return path;
  20. }
  21.  
  22. chdir(path)
  23. char *path;
  24. {
  25.     BPTR Lock(), AttemptLock, CurrentDir();
  26.     long PathName(), len;
  27.     struct FileInfoBlock *fib;
  28.     void *AllocMem();
  29.     int retval;
  30.  
  31.     AttemptLock = Lock(path, ACCESS_READ);
  32.     if (!AttemptLock)
  33.         return -1;
  34.     fib = (struct FileInfoBlock *) AllocMem((long)
  35.                             sizeof(struct FileInfoBlock),
  36.                         MEMF_CLEAR);
  37.     Examine(AttemptLock, fib);
  38.     if (fib->fib_DirEntryType < 0) {
  39.         retval = -1;
  40.         UnLock(AttemptLock);
  41.         goto clean;
  42.     }
  43.     UnLock(CurrentDir(AttemptLock));    /* do the thing        */
  44.     if (PathName(AttemptLock, MyDirName, MAXPATH/31L) == 0)
  45.         MyDirName[0] = '\0';
  46.     retval = 0;                /* Success!        */
  47.     clean:
  48.     FreeMem((void *) fib, (long) sizeof(struct FileInfoBlock));
  49.     return retval;
  50. }
  51. #endif
  52.